package modifier.tile;

import board.Tile;
import character.MyCharacter;
import effect.Effect;

public class TileModifierWalk extends TileModifier {
    protected Effect tileWalkEffect;
    
    public TileModifierWalk(MyCharacter owner, Effect tileWalkEffect, int duration) {
        super(owner, duration);
        this.tileWalkEffect = tileWalkEffect;
    }

    @Override
    protected void apply() {
        super.apply();
        System.out.println("Applying walk effect to tile...");
	tile.addTileWalkEffect(tileWalkEffect);
    }

    @Override
    protected void tick() {
        super.tick();
    }

    @Override
    protected void completeNaturally() {
        super.completeNaturally();
        removeWalkEffect();
    }

    @Override
    protected void abort() {
        super.abort();
        removeWalkEffect();
    }
    
    protected void removeWalkEffect() {
        System.out.println("Removing tile walk effect...");
        tile.removeTileWalkEffect(tileWalkEffect);
    }
    
    public Effect getEffect() {
        return tileWalkEffect;
    }

    @Override
    public TileModifier cloneForTile(Tile tile) {
        TileModifierWalk clone = new TileModifierWalk(owner, tileWalkEffect.clone(), totalTicks);
        cloneMeForTile(clone, tile);
        return clone;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TileModifierWalk other = (TileModifierWalk) obj;
        if (this.tileWalkEffect != other.tileWalkEffect && (this.tileWalkEffect == null || !this.tileWalkEffect.equals(other.tileWalkEffect))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 83 * hash + (this.tileWalkEffect != null ? this.tileWalkEffect.hashCode() : 0);
        return hash;
    }
}
